package com.ibiaoke.order.service;

import com.ibiaoke.common.response.Res;
import com.ibiaoke.common.utils.AssertUtils;
import com.ibiaoke.customer.consts.PayTypeConst;
import com.ibiaoke.customer.consts.TradeTypeConsts;
import com.ibiaoke.customer.entity.TradeRecorder;
import com.ibiaoke.customer.service.TradeRecorderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Map;
import java.util.Objects;

@Service
public class xcxDepositServiceImpl implements xcxDepositService{

    @Autowired
    private TradeRecorderService tradeRecorderService;

    @Autowired
    private XcxPayOrderService xcxPayOrderService;

    @Override
    public Res xcxDepositCharge(Integer customerId, BigDecimal money, Integer payType, String openId, String ip) {
        AssertUtils.notNull(customerId, "用户id不能为空");
        AssertUtils.notNull(money, "充值金额不能为空");
        TradeRecorder tradeRecorder = tradeRecorderService.createTradeRecorder(customerId, payType, money, TradeTypeConsts.CHARGE);
        if (Objects.equals(PayTypeConst.WECAHT, payType)){
            Map<String, String> payInfo = xcxPayOrderService.payDepositChargeByWe(tradeRecorder, openId);
            return Res.create().addResponse("payInfo", payInfo);
        }
        return null;
    }
}
